<?php

namespace Database\Factories\System;

use App\Models\System\Admin;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\System\Admin>
 */
class AdminFactory extends Factory
{
    protected static ?string $password;

    protected static int $index = 0;

    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        if (self::$index == 0) {
            $maxId = Admin::query()->orderByDesc('id')->first('id');
            self::$index = $maxId?->id ?: 0;
        }
        $index = static::$index++;

        return [
            'username' => 'admin'.$index,
            'password' => Hash::make('123456'),
            'avatar' => '/assets/img/avatar.png',
            'nickname' => '管理员'.$index,
            'status' => 'normal',
        ];
    }

    public function disabled(): static
    {
        return $this->state(fn (array $attributes) => [
            'status' => 'disabled',
        ]);
    }
}
